import React, { Component } from "react"
import { Form, Radio, Modal, Tooltip } from "antd"
import { QuestionCircleFilled } from "@ant-design/icons"
import EditInput from './component/editInput';
import TheButton from '@/components/TheButton';
import TheSwitch from '@/components/TheSwitch';
import { cloneDeep } from 'lodash';
import { rechargeWithdrawList, rechargeWithdrawEdit, apiRiskConfigList, apiRiskConfigAddOrUpdate } from '@/request/wallet/rechargeWithdraw'
import WalletRestrictions from "../depositSettings/component/allLimit";
import { limit } from "../depositSettings/enum"

const DayAmountLabel = () => (
  <span>
    单人单日赠送总额度
    <Tooltip title="指接收方每日接收礼物的最大额度（元）。超出后，发送方发送礼物时会提示对应文案。" ><QuestionCircleFilled /></Tooltip>
  </span>
)

const DayReceiveAmount = () => (
  <span>
    单人单日接收总额度
    <Tooltip title="指发送方每日发送礼物的最大额度（元）。超出后，发送方发送礼物时会提示对应文案。" ><QuestionCircleFilled /></Tooltip>
  </span>
)
export default class Transfer extends Component {
  ChildRef = React.createRef();
  ChildRef2 = React.createRef();
  ChildRef3 = React.createRef();
  ChildRef4 = React.createRef();
  state = {
    isNewPay: false,//
    newPaySwitch: false,//新人钱包充值限制开关
    newPayArr: [],//新人钱包充值限制数据
    title: "单日接收转账额度",
    arr: [],//弹窗的数据
    isNewPay2: false,//
    newPaySwitch2: false,//新人钱包充值限制开关
    newPayArr2: [],//新人钱包充值限制数据
    title2: "单日接收红包额度",
    arr2: [],//弹窗的数据
    isNewPay3: false,//
    newPaySwitch3: false,//新人钱包充值限制开关
    newPayArr3: [],//新人钱包充值限制数据
    title3: "单日接收礼物金额额度",
    arr3: [],//弹窗的数据
    redPacket: {},// 红包
    transfer: {},// 转账
    giftData: {}, // 礼物
    redPacketType: null, //红包入口是否展示
    transferType: null, //转账入口是否展示
    moneyLimit: {},// 转账过大验证码验证最大额度
    moneyVerification: '', // 转账过大验证码验证最大额度开关
    replacementEquipment: '', // 更换常用设备时转账手机验证码开关
    transferAccountsType: '', //红包转账入口状态
    isInputChange: false,//是否修改值
    oldInput: '',//旧数据输入框
    redPacketId: '',//红包id
    transferId: '',//转账id
    newLimitId: "",//新人接收礼物限制id
    newPayArr1: [],//新人钱包充值限制数据
    newPaySwitchSend: false,
    isShow4: false,
    newPaySwitch2Send: false,
    newPayArr2Send: [],//新人钱包充值限制数据
    newPaySwitch3Send: false,
    newPayArr3Send: [],//新人钱包充值限制数据
    upDateTitle: '',
  }
  componentDidMount() {
    this.getRedPacketData()
    this.getTransferData()
    this.getRealNameAuthenticationData()
    this.getRedData()
    this.getNewLimit()
    this.getNewPay(limit["单日接收转账额度"])
    this.getNewPay2(limit["单日接收红包额度"])
    this.getNewPay3(limit["单日接收礼物金额额度"])
  }
  // 获取转账数据
  getTransferData = async () => {
    let res = await rechargeWithdrawList({ type: 3 })
    if (res.code === 0 && res.data) {
      let data = res.data
      this.setState({
        newPaySwitch: data.newMemberRiskSwitch,
        newPaySwitchSend: data.newMemberSendRiskSwitch,
        transfer: {
          minimumAmount: {
            label: '单人单次发送最低金额',
            key: 'minimumAmount',
            value: (data.minimumAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          maximumAmount: {
            label: '单人单次发送最高金额',
            key: 'maximumAmount',
            value: (data.maximumAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayAmount: {
            label: '单人单日发送总额度',
            key: 'dayAmount',
            value: (data.dayAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayReceiveAmount: {
            label: '单人单日接收总额度',
            key: 'dayReceiveAmount',
            value: (data.dayReceiveAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayNumber: {
            label: '单人单日发送最大次数',
            key: 'dayNumber',
            value: data.dayNumber,
            minValue: 1,
            maxValue: 10000,
            precision: 0,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'次'
          },
        },
        transferId: data.imAmountConfigId,
        transferType: data.transferAccountsType,
        replacementEquipment: data.replacementEquipment === 0 ? true : false,
        moneyVerification: data.moneyVerification === 0 ? true : false,
        moneyLimit: {
          label: '触发验证的最大金额额度',
          key: 'moneyLimit',
          value: (data.moneyLimit / 100).toFixed(2),
          minValue: 0.01,
          maxValue: 999999.99,
          precision: 2,
          status: 0, //编辑 0 保存1
        },
      })
    }
  };
  // 获取红包实名认证数据
  getRealNameAuthenticationData = async () => {
    let res = await rechargeWithdrawList({ type: 6 })
    if (res.code === 0 && res.data) {
      let data = res.data
      this.setState({
        redEntrySwitch: data.entrySwitch,//红包实名
      })
    }
  };
  // 获取转账实名认证数据
  getRedData = async () => {
    let res = await rechargeWithdrawList({ type: 7 })
    if (res.code === 0 && res.data) {
      let data = res.data
      this.setState({
        transferEntrySwitch: data.entrySwitch,//转账实名
      })
    }
  };
  // 获取红包数据
  getRedPacketData = async () => {
    let res = await rechargeWithdrawList({ type: 2 })
    if (res.code === 0 && res.data) {
      let data = res.data
      this.setState({
        newPaySwitch2: data.newMemberRiskSwitch,
        newPaySwitch2Send: data.newMemberSendRiskSwitch,
        redPacket: {
          minimumAmount: {
            label: '单人单次发送最低金额',
            key: 'minimumAmount',
            value: (data.minimumAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          maximumAmount: {
            label: '单人单次发送最高金额',
            key: 'maximumAmount',
            value: (data.maximumAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayAmount: {
            label: '单人单日发送总额度',
            key: 'dayAmount',
            value: (data.dayAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayReceiveAmount: {
            label: '单人单日接收总额度',
            key: 'dayReceiveAmount',
            value: (data.dayReceiveAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayNumber: {
            label: '单人单日发送最大次数',
            key: 'dayNumber',
            value: data.dayNumber,
            minValue: 1,
            maxValue: 10000,
            precision: 0,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'次'
          },
        },
        redPacketId: data.imAmountConfigId,
        redPacketType: data.transferAccountsType
      })
    }
  };
  // 获取红包数据
  getNewLimit = async () => {
    let res = await rechargeWithdrawList({ type: 8 })
    if (res.code === 0 && res.data) {
      let data = res.data
      this.setState({
        giftData: {
          dayAmount: {
            label: <DayAmountLabel />,
            key: 'dayAmount',
            value: (data.dayAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
          dayReceiveAmount: {
            label: <DayReceiveAmount />,
            key: 'dayReceiveAmount',
            value: (data.dayReceiveAmount / 100).toFixed(2),
            minValue: 0.01,
            maxValue: 999999.99,
            precision: 2,
            status: 0, //编辑 0 保存1
            bgColor: false,
            unit:'元'
          },
        },
        newPaySwitch3: data.newMemberRiskSwitch,
        newPaySwitch3Send: data.newMemberSendRiskSwitch,
        newLimitId: data.imAmountConfigId,
      })
    }
  };
  // 修改转账入口状态
  transferStatusChange = async (e) => {
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: this.state.transferId, transferAccountsType: e.target.value
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: '保存成功' })
      this.getTransferData()
    }
  }
  // 修改红包入口状态
  redPacketStatusChange = async (e) => {
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: this.state.redPacketId, transferAccountsType: e.target.value
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: '保存成功' })
      this.getRedPacketData()
    }
  }
  // 更换设备时是否开启验证码
  replacementEquipmentSwitch = async (e) => {
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: this.state.transferId, replacementEquipment: e ? 0 : 1
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: !e ? '关闭成功' : '开启成功' })
      this.getTransferData()
    }
  }
  // 转账实名认证
  transferSwitch = async (e) => {
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: this.state.transferId, entrySwitch: e ? 0 : 1, type: 7
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: !e ? '关闭成功' : '开启成功' })
      this.getRedData()
    }
  }
  // 红包实名认证
  redSwitch = async (e) => {
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: this.state.transferId, entrySwitch: e ? 0 : 1, type: 6
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: !e ? '关闭成功' : '开启成功' })
      this.getRealNameAuthenticationData()
    }
  }
  // 金额过大时是否开启验证码
  moneyVerificationSwitch = async (e) => {
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: this.state.transferId, moneyVerification: e ? 0 : 1
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: !e ? '关闭成功' : '开启成功' })
      this.getTransferData()
    }
    this.setState({
      isMaxMoneyFlag: e
    })
  }
  // 保存时掉接口
  saveFn = async (params, v, id) => {
    let data = v.precision === 0 ? params.data.value : React.$transNum(params.data.value, 0, 2)
    let res = await rechargeWithdrawEdit({
      imAmountConfigId: id, [v.key]: data
    })
    if (res.code === 0) {
      React.$message({ type: 'success', content: '保存成功' })
      v.status = 0
      this.getTransferData()
      this.getRedPacketData()
      return v
    }
  }
  // 金额校验规则
  moneyReg = (params, defaultParams, id) => {
    let numValues = Number(params.data.value)
    Object.values(defaultParams).map((v, i) => {
      if (params.index === i) {
        if (params.data.key === 'maximumAmount') {
          if (numValues <= Number(defaultParams.minimumAmount.value)) {
            Modal.error({
              content: '单次最高金额不能小于或等于单次最低金额',
              okText: '确定'
            });
            return
          } else if (numValues > Number(defaultParams.dayAmount.value)) {
            Modal.warning({
              content: '单次最高金额不能大于单日总额度',
              okText: '确定'
            });
            return
          } else if ((numValues * Number(defaultParams.dayNumber.value)) < Number(defaultParams.dayAmount.value)) {
            Modal.confirm({
              title: '提示',
              content: '修改后， 单人单次发送最高金额*单人单日发送最大次数的总额<单人单日发送总额度 ，会导致单人单日发送总额度的数值无实际意义，确认继续吗',
              onOk: () => {
                this.saveFn(params, v, id)
              },
            });
          } else {
            this.saveFn(params, v, id)
          }
        } else if (params.data.key === 'minimumAmount') {
          if (numValues >= Number(defaultParams.maximumAmount.value)) {
            Modal.warning({
              content: '单次最低金额不能大于或等于单次最高金额',
              okText: '确定'
            });
            return
          } else {
            this.saveFn(params, v, id)
          }
        } else if (params.data.key === 'dayAmount') {
          if (defaultParams.maximumAmount) {
            if (numValues < Number(defaultParams.maximumAmount.value)) {
              Modal.error({
                content: '单次最高金额不能大于单日总额度',
                okText: '确定'
              });
              return
            } else if (numValues > (Number(defaultParams.maximumAmount.value) * Number(defaultParams.dayNumber.value))) {
              Modal.confirm({
                title: '提示',
                content: '修改后， 单人单次发送最高金额*单人单日发送最大次数的总额<单人单日发送总额度 ，会导致单人单日发送总额度的数值无实际意义，确认继续吗',
                onOk: () => {
                  this.saveFn(params, v, id)
                },
              });
            } else {
              this.saveFn(params, v, id)
            }
          } else {
            this.saveFn(params, v, id)
          }
        } else if (params.data.key === "dayNumber") {
          if ((Number(defaultParams.maximumAmount.value) * numValues) < Number(defaultParams.dayAmount.value)) {
            Modal.confirm({
              title: '提示',
              content: '修改后， 单人单次发送最高金额*单人单日发送最大次数的总额<单人单日发送总额度 ，会导致单人单日发送总额度的数值无实际意义，确认继续吗',
              onOk: () => {
                this.saveFn(params, v, id)
              },
            });
          } else {
            this.saveFn(params, v, id)
          }
        } else {
          this.saveFn(params, v, id)
        }
        // v.status = 0
        v.value = params.data.value
        return v
      }
    })
  }
  // 转账保存
  transferSave = (params) => {
    let { transfer, transferId } = this.state
    this.moneyReg(params, transfer, transferId)
  }
  // 转账编辑
  transferEdit = (params) => {
    let { transfer, redPacket } = this.state
    let data = ""
    Object.values(transfer).map((v, i) => {
      if (params.index === i) {
        data = v.value
        return v.status = 1
      } else {
        if (v.status === 1) {
          v.value = this.state.oldInput
        }
        v.status = 0
        Object.values(redPacket).map((v, i) => {
          return v.status = 0
        })
        this.state.moneyLimit.status = 0
        return v
      }
    })
    this.setState({
      transfer: cloneDeep(transfer),
      oldInput: data,
      redPacket: cloneDeep(redPacket),
    })
  }
  // 转账取消
  transferCancel = (params) => {
    let { transfer, isInputChange } = this.state
    Object.values(transfer).map((v, i) => {
      if (params.index === i) {
        // if (isInputChange) {
        //   this.getTransferData()
        // }
        return v.status = 0
      }
    })
    this.setState({
      transfer: cloneDeep(transfer)
    })
  }
  // 红包保存
  redPacketSave = (params) => {
    let { redPacket, redPacketId } = this.state
    this.moneyReg(params, redPacket, redPacketId)
  }
  // 红包编辑
  redPacketEdit = (params) => {
    let { redPacket, transfer } = this.state
    Object.values(redPacket).map((v, i) => {
      if (params.index === i) {
        return v.status = 1
      } else {
        this.state.moneyLimit.status = 0
        Object.values(transfer).map((v) => { return v.status = 0 })
        return v.status = 0
      }
    })
    this.setState({
      transfer: cloneDeep(transfer),
      redPacket: cloneDeep(redPacket)
    })
  }
  //红包取消 
  redPacketCancel = (params) => {
    let { redPacket } = this.state
    Object.values(redPacket).map((v, i) => {
      if (params.index === i) {
        return v.status = 0
      }
    })
    this.setState({
      redPacket: cloneDeep(redPacket)
    })
  }
  // 礼物保存
  giftSettingSave = (params) => {
    console.log(params, 'params');
    let { giftData, newLimitId } = this.state
    this.moneyReg(params, giftData, newLimitId)
  }
  // 礼物编辑
  giftSettingEdit = (params) => {
    let { giftData, transfer } = this.state
    Object.values(giftData).map((v, i) => {
      if (params.index === i) {
        return v.status = 1
      } else {
        this.state.moneyLimit.status = 0
        Object.values(transfer).map((v) => { return v.status = 0 })
        return v.status = 0
      }
    })
    this.setState({
      transfer: cloneDeep(transfer),
      giftData: cloneDeep(giftData)
    })
  }
  //礼物取消 
  giftSettingCancel = (params) => {
    let { giftData } = this.state
    Object.values(giftData).map((v, i) => {
      if (params.index === i) {
        return v.status = 0
      }
    })
    this.setState({
      giftData: cloneDeep(giftData)
    })
  }
  // 验证码超出最大金额时验证 保存
  moneyLimitSave = async (params) => {
    let { moneyLimit, transferId } = this.state
    let res = await rechargeWithdrawEdit({ imAmountConfigId: transferId, moneyLimit: React.$transNum(params.data.value, 0, 2) })
    if (res.code === 0) {
      this.setState({
        moneyLimit: {
          ...moneyLimit,
          value: params.data.value,
          status: 0
        }
      })
      React.$message({ type: 'success', content: '保存成功' })
      this.getTransferData()

    }
  }
  // 验证码超出最大金额时验证 编辑
  moneyLimitEdit = () => {
    let { moneyLimit, transfer, redPacket } = this.state
    moneyLimit.status = 1
    Object.values(transfer).map((v) => { return v.status = 0 })
    Object.values(redPacket).map((value) => { return value.status = 0 })
    this.setState({
      transfer: cloneDeep(transfer),
      redPacket: cloneDeep(redPacket),
      moneyLimit: cloneDeep(moneyLimit)
    })
  }
  // 验证码超出最大金额时验证 取消
  moneyLimitCancel = () => {
    let { moneyLimit } = this.state
    moneyLimit.status = 0
    this.setState({
      moneyLimit
    })
  }
  //点编辑打开弹窗
  showModalNewPay = () => {
    this.setState({
      isShow: false
    }, () => {
      this.setState({
        arr: this.state.newPayArr,
        isShow: true
      }, () => {
        this.ChildRef.current.control(true)
      })
    })
  }
  showModalNewPaySend = (title, arr, tips) => {
    let upDateTitle
    switch (title) {
      case '单日发送转账额度':
        upDateTitle = '单日接收转账额度'
        break;
      case '单日发送红包额度':
        upDateTitle = '单日接收红包额度'
        break;
      case '新人赠送礼物限制':
        upDateTitle = '单日接收礼物金额额度'
        break;
      default:
        break;
    }
    this.setState({
      isShow4: false
    }, () => {
      this.setState({
        isShow4: true,
        titleNum: title,
        arr4: arr,
        tips,
        upDateTitle,
      }, () => {
        this.ChildRef4.current.control(true)
      })
    })
  }
  //获取新人钱包充值限制数据
  getNewPay = async (configType) => {
    let res = await apiRiskConfigList({ configType, configChildType: 0 })
    if (res.code === 0 && res.data) {
      this.setState({
        newPayArr: res.data.list.map(item => {
          return {
            ...item,
            amountPerDay: React.$transNum(item.amountPerDay, 0, -2)
          }
        })
      })
    }
    let request = await apiRiskConfigList({ configType, configChildType: 1 })
    if (request.code === 0 && request.data) {
      this.setState({
        newPayArr1: request.data.list.map(item => {
          return {
            ...item,
            amountPerDay: React.$transNum(item.amountPerDay, 0, -2)
          }
        })
      })
    }
  }
  //保存弹窗后更新数据
  saveModal = async (params) => {
    const { title } = this.state
    let current = limit[title]
    const newVal = params.map(item => {
      delete item.id
      return {
        configType: current,
        configChildType: 0,
        ...item,
        amountPerDay: React.$transNum(item.amountPerDay, 0, 2)
      }
    })
    let res = await apiRiskConfigAddOrUpdate(newVal)
    if (res.code === 0) {
      this.getNewPay(current)
      this.ChildRef.current.control(false)
      React.$message({ type: 'success', content: '保存成功' })
    }
  }
  //保存弹窗后更新数据
  saveModal4 = async (params) => {
    const { upDateTitle } = this.state
    let current = limit[upDateTitle]
    const newVal = params.map(item => {
      delete item.id
      return {
        configType: current,
        configChildType: 1,
        ...item,
        amountPerDay: React.$transNum(item.amountPerDay, 0, 2)
      }
    })
    let res = await apiRiskConfigAddOrUpdate(newVal)
    if (res.code === 0) {
      switch (current) {
        case 3:
          this.getNewPay(current)
          break;
        case 2:
          this.getNewPay2(current)
          break;
        case 8:
          this.getNewPay3(current)
          break;
        default:
          break;
      }
      this.ChildRef4.current.control(false)
      React.$message({ type: 'success', content: '保存成功' })
    }
  }

  //新人钱包充值限制开关
  newPay = async (flag) => {
    if (flag && this.state.newPayArr.length == 0) {
      //0条打开编辑弹窗
      this.showModalNewPay()
      return
    } else {
      let res = await rechargeWithdrawEdit({
        imAmountConfigId: this.state.transferId,
        newMemberRiskSwitch: ~~flag
      })
      if (res.code === 0) {
        React.$message({ type: 'success', content: '保存成功' })
        this.getNewPay(limit["单日接收转账额度"])
        this.setState({
          newPaySwitch: flag
        })
      }
    }
  }
  //新人发送转账限制开关
  newPaySend = async (flag) => {
    if (flag && this.state.newPayArr1.length === 0) {
      //0条打开编辑弹窗
      this.showModalNewPaySend('单日发送转账额度', [], '编辑新人发送转账限制')
      return
    } else {
      let res = await rechargeWithdrawEdit({
        imAmountConfigId: this.state.transferId,
        newMemberSendRiskSwitch: ~~flag
      })
      if (res.code === 0) {
        React.$message({ type: 'success', content: '保存成功' })
        this.getNewPay(limit["单日接收转账额度"])
        this.setState({
          newPaySwitchSend: flag
        })
      }
    }
  }
  //点编辑打开弹窗
  showModalNewPay2 = () => {
    this.setState({
      isShow2: false
    }, () => {
      this.setState({
        arr2: this.state.newPayArr2,
        isShow2: true
      }, () => {
        this.ChildRef2.current.control(true)
      })
    })
  }
  //获取新人钱包充值限制数据
  getNewPay2 = async (configType) => {
    let res = await apiRiskConfigList({ configType, configChildType: 0 })
    if (res.code === 0 && res.data) {
      this.setState({
        newPayArr2: res.data.list.map(item => {
          return {
            ...item,
            amountPerDay: React.$transNum(item.amountPerDay, 0, -2)
          }
        }),

      })
    }
    let request = await apiRiskConfigList({ configType, configChildType: 1 })
    if (request.code === 0 && request.data) {
      this.setState({
        newPayArr2Send: request.data.list.map(item => {
          return {
            ...item,
            amountPerDay: React.$transNum(item.amountPerDay, 0, -2)
          }
        }),

      })
    }
  }
  //保存弹窗后更新数据
  saveModal2 = async (params) => {
    const { title2 } = this.state
    let current = limit[title2]
    const newVal = params.map(item => {
      delete item.id
      return {
        configType: current,
        ...item,
        amountPerDay: React.$transNum(item.amountPerDay, 0, 2)
      }
    })
    let res = await apiRiskConfigAddOrUpdate(newVal)
    if (res.code === 0) {
      this.getNewPay2(current)
      this.ChildRef2.current.control(false)
      React.$message({ type: 'success', content: '保存成功' })
    }
  }

  //新人钱包充值限制开关
  newPay2 = async (flag) => {
    if (flag && this.state.newPayArr2.length == 0) {
      //0条打开编辑弹窗
      this.showModalNewPay2()
      return
    } else {
      let res = await rechargeWithdrawEdit({
        imAmountConfigId: this.state.redPacketId,
        newMemberRiskSwitch: ~~flag
      })
      if (res.code === 0) {
        React.$message({ type: 'success', content: '保存成功' })
        this.getNewPay(limit["单日接收红包额度"])
        this.setState({
          newPaySwitch2: flag
        })
      }
    }
  }
  newPay2Send = async (flag) => {
    if (flag && this.state.newPayArr2Send.length == 0) {
      //0条打开编辑弹窗
      this.showModalNewPaySend('单日发送红包额度', [], '编辑新人发送红包限制')
      return
    } else {
      let res = await rechargeWithdrawEdit({
        imAmountConfigId: this.state.redPacketId,
        newMemberSendRiskSwitch: ~~flag
      })
      if (res.code === 0) {
        React.$message({ type: 'success', content: '保存成功' })
        this.getNewPay(limit["单日接收红包额度"])
        this.setState({
          newPaySwitch2Send: flag
        })
      }
    }
  }
  //点编辑打开弹窗
  showModalNewPay3 = () => {
    this.setState({
      isShow3: false
    }, () => {
      this.setState({
        arr3: this.state.newPayArr3,
        isShow3: true
      }, () => {
        this.ChildRef3.current.control(true)
      })
    })
  }
  //获取新人钱包充值限制数据
  getNewPay3 = async (configType) => {
    let res = await apiRiskConfigList({ configType, configChildType: 0 })
    if (res.code === 0 && res.data) {
      this.setState({
        newPayArr3: res.data.list.map(item => {
          return {
            ...item,
            amountPerDay: React.$transNum(item.amountPerDay, 0, -2)
          }
        })
      })
    }
    let request = await apiRiskConfigList({ configType, configChildType: 1 })
    if (request.code === 0 && request.data) {
      this.setState({
        newPayArr3Send: request.data.list.map(item => {
          return {
            ...item,
            amountPerDay: React.$transNum(item.amountPerDay, 0, -2)
          }
        })
      })
    }
  }
  //保存弹窗后更新数据
  saveModal3 = async (params) => {
    const { title3 } = this.state
    let current = limit[title3]
    const newVal = params.map(item => {
      delete item.id
      return {
        configType: current,
        ...item,
        amountPerDay: React.$transNum(item.amountPerDay, 0, 2)
      }
    })
    let res = await apiRiskConfigAddOrUpdate(newVal)
    if (res.code === 0) {
      this.getNewPay3(current)
      this.ChildRef3.current.control(false)
      React.$message({ type: 'success', content: '保存成功' })
    }
  }

  //新人钱包充值限制开关
  newPay3 = async (flag) => {
    if (flag && this.state.newPayArr3.length == 0) {
      //0条打开编辑弹窗
      this.showModalNewPay3()
      return
    } else {
      let res = await rechargeWithdrawEdit({
        imAmountConfigId: this.state.newLimitId,
        newMemberRiskSwitch: ~~flag
      })
      if (res.code === 0) {
        React.$message({ type: 'success', content: '保存成功' })
        this.getNewPay(limit["单日接收礼物金额额度"])
        this.setState({
          newPaySwitch3: flag
        })
      }
    }
  }
  newPay3Send = async (flag) => {
    if (flag && this.state.newPayArr3Send.length == 0) {
      //0条打开编辑弹窗
      this.showModalNewPaySend('新人赠送礼物限制', [], '编辑新人赠送礼物限制')
      return
    } else {
      let res = await rechargeWithdrawEdit({
        imAmountConfigId: this.state.newLimitId,
        newMemberSendRiskSwitch: ~~flag
      })
      if (res.code === 0) {
        React.$message({ type: 'success', content: '保存成功' })
        this.getNewPay(limit["单日接收礼物金额额度"])
        this.setState({
          newPaySwitch3Send: flag
        })
      }
    }
  }
  render() {
    const { arr3, title3, isShow3, newPayArr3, newPaySwitch3, isShow2, isNewPay2, newPaySwitch2,
      newPayArr2, title2, arr2, newPaySwitch, newPayArr, isShow, title, arr, redPacket, transfer, newPayArr1,
      moneyLimit, moneyVerification, replacementEquipment, transferType, redPacketType, transferEntrySwitch,
      redEntrySwitch, giftData, newPaySwitchSend, isShow4, tips, titleNum, arr4, newPaySwitch2Send, newPayArr2Send,
      newPayArr3Send, newPaySwitch3Send } = this.state
    return (
      <div className="p-layout-box commodity-examine" >
        <div style={{ display: 'flex', marginLeft: 30, alignItems: 'baseline' }}>
          <div style={{ marginRight: 50, fontSize: 14, minWidth: '60px' }}>转账设置</div>
          <Form
            style={{ flex: 1 }}
            labelAlign="left"
            colon={false}
            labelWrap
            labelCol={{
              span: 8,
            }}
            wrapperCol={{
              span: 10
            }}
          >
            <Form.Item
              style={{ marginBottom: 10 }}
              label="转账入口"
            >
              <Radio.Group value={transferType} onChange={(e) => this.transferStatusChange(e)}>
                <Radio value={0}>展示</Radio>
                <Radio value={1}>隐藏</Radio>
              </Radio.Group>
            </Form.Item>
            {Object.values(transfer).map((item, index) => {
              return (
                <Form.Item
                  style={{ marginBottom: 10 }}
                  label={item.label}
                >
                  <EditInput editData={item} editIdex={index} onEdit={this.transferEdit} onSave={this.transferSave} onCancel={this.transferCancel} />
                </Form.Item>
              )
            })}
            {/* <div style={{ marginBottom: 20 }}><span style={{ marginRight: 10 }}>更换常用设备时转账手机验证码验证</span>
              <Switch checked={replacementEquipment} onChange={(e) => this.replacementEquipmentSwitch(e)} />
            </div> */}
            <div style={{ marginBottom: 10 }}>
              <span style={{ marginRight: 10 }}>实名认证</span>
              <TheSwitch haspermi={["wallet:setting:realName"]} checked={transferEntrySwitch == 0 ? true : false} onChange={(e) => this.transferSwitch(e)} />
            </div>
            <div style={{ marginBottom: 10 }}>
              <span style={{ marginRight: 10 }}>转账金额过大时手机验证码验证</span>
              <TheSwitch haspermi={["wallet:setting:whenItIsTooLarge"]} checked={moneyVerification} onChange={(e) => this.moneyVerificationSwitch(e)} />
            </div>
            {
              moneyVerification ? <div style={{ marginBottom: 10, display: 'flex', alignItems: 'center' }}>
                <span style={{ marginRight: 10 }}>触发验证的最大金额额度</span>
                <EditInput editData={moneyLimit} onEdit={this.moneyLimitEdit} onSave={this.moneyLimitSave} onCancel={this.moneyLimitCancel} />
              </div>
                : null
            }
            <div style={{ marginTop: '20px' }}>
              <span style={{ marginRight: '20px' }}>新人接收转账限制</span>
              <TheSwitch haspermi={["wallet:setting:newRetract"]} checked={newPaySwitch} onChange={this.newPay} />
            </div>
            <div style={{ marginTop: '20px', width: '80vw' }}>
              {
                newPayArr.map(item => {
                  return <div >
                    新人注册第【{item.startDay}-{item.endDay}】天，单日接收转账额度为【{item.amountPerDay}】元，超出后提示文案为【{item.noticeMessage}】
                  </div>
                })
              }
            </div>
            <div style={{ marginTop: '20px', paddingLeft: '300px' }}>
              <TheButton haspermi={["wallet:setting:newRetractEdit"]} type="primary" onClick={this.showModalNewPay}>编辑</TheButton>
            </div>
            <div style={{ marginTop: '20px' }}>
              <span style={{ marginRight: '20px' }}>新人发送转账限制</span>
              <TheSwitch haspermi={["wallet:setting:newRetractSend"]} checked={newPaySwitchSend} onChange={this.newPaySend} />
            </div>
            <div style={{ marginTop: '20px', width: '80vw' }}>
              {
                newPayArr1.map(item => {
                  return <div >
                    新人注册第【{item.startDay}-{item.endDay}】天，单日发送转账额度为【{item.amountPerDay}】元，超出后提示文案为【{item.noticeMessage}】
                  </div>
                })
              }
            </div>
            <div style={{ marginTop: '20px', paddingLeft: '300px' }}>
              <TheButton haspermi={["wallet:setting:newRetractEditSend"]} type="primary" onClick={() => this.showModalNewPaySend('单日发送转账额度', newPayArr1, '编辑新人发送转账限制')}>编辑</TheButton>
            </div>
            {isShow && <WalletRestrictions ref={this.ChildRef} title={title} arr={arr} save={this.saveModal} tips="编辑新人接收转账限制" />}
          </Form>
        </div>
        <div style={{ display: 'flex', marginLeft: 30, marginTop: 40, alignItems: 'baseline' }}>
          <div style={{ marginRight: 50, fontSize: 14, minWidth: '60px' }}>红包设置</div>
          <Form
            style={{ flex: 1 }}
            labelAlign="left"
            colon={false}
            labelWrap
            labelCol={{
              span: 8,
            }}
            wrapperCol={{
              span: 10
            }}
          >
            <Form.Item
              style={{ marginBottom: 10 }}
              label="红包入口"
            // name="redPacketType"
            >
              <Radio.Group value={redPacketType} onChange={(e) => this.redPacketStatusChange(e)}>
                <Radio value={0}>展示</Radio>
                <Radio value={1}>隐藏</Radio>
              </Radio.Group>
            </Form.Item>
            {Object.values(redPacket).map((item, index) => {
              return (
                <Form.Item
                  style={{ marginBottom: 10 }}
                  label={item.label}
                  name={item.key}
                >
                  <EditInput editData={item} editIdex={index} onEdit={this.redPacketEdit} onSave={this.redPacketSave} onCancel={this.redPacketCancel} />
                </Form.Item>
              )
            })}
            <div style={{ marginBottom: 10 }}>
              <span style={{ marginRight: 10 }}>实名认证</span>
              <TheSwitch haspermi={["wallet:setting:redRealName"]} checked={redEntrySwitch == 0 ? true : false} onChange={(e) => this.redSwitch(e)} />
            </div>
            <div style={{ marginTop: '20px' }}>
              <span style={{ marginRight: '20px' }}>新人接收红包限制</span>
              <TheSwitch haspermi={["wallet:setting:newRedSwitch"]} checked={newPaySwitch2} onChange={this.newPay2} />
            </div>
            <div style={{ marginTop: '20px', width: '80vw' }}>
              {
                newPayArr2.map(item => {
                  return <div>
                    新人注册第【{item.startDay}-{item.endDay}】天，单日接收红包额度为【{item.amountPerDay}】元，超出后提示文案为【{item.noticeMessage}】
                  </div>
                })
              }
            </div>
            <div style={{ marginTop: '20px', paddingLeft: '300px' }}>
              <TheButton haspermi={["wallet:setting:redEdit"]} type="primary" onClick={this.showModalNewPay2}>编辑</TheButton>
            </div>
            <div style={{ marginTop: '20px' }}>
              <span style={{ marginRight: '20px' }}>新人发送红包限制</span>
              <TheSwitch haspermi={["wallet:setting:newRedSwitchSend"]} checked={newPaySwitch2Send} onChange={this.newPay2Send} />
            </div>
            <div style={{ marginTop: '20px', width: '80vw' }}>
              {
                newPayArr2Send.map(item => {
                  return <div>
                    新人注册第【{item.startDay}-{item.endDay}】天，单日发送红包额度为【{item.amountPerDay}】元，超出后提示文案为【{item.noticeMessage}】
                  </div>
                })
              }
            </div>
            <div style={{ marginTop: '20px', paddingLeft: '300px' }}>
              <TheButton haspermi={["wallet:setting:redEditSend"]} type="primary" onClick={() => this.showModalNewPaySend('单日发送红包额度', newPayArr2Send, '编辑新人发送红包限制')}>编辑</TheButton>
            </div>
            {isShow2 && <WalletRestrictions ref={this.ChildRef2} title={title2} arr={arr2} save={this.saveModal2} tips="编辑新人接收红包限制" />}
          </Form>
        </div>
        <div style={{ display: 'flex', marginLeft: 30, marginTop: 40, alignItems: 'baseline' }}>
          <div style={{ marginRight: 50, fontSize: 14, minWidth: '60px' }}>礼物设置</div>
          <Form
            style={{ flex: 1 }}
            labelAlign="left"
            colon={false}
            labelWrap
            labelCol={{
              span: 8,
            }}
            wrapperCol={{
              span: 10
            }}
          >
            {Object.values(giftData).map((item, index) => {
              return (
                <Form.Item
                  style={{ marginBottom: 10 }}
                  label={item.label}
                  name={item.key}
                >
                  <EditInput editData={item} editIdex={index} onEdit={this.giftSettingEdit} onSave={this.giftSettingSave} onCancel={this.giftSettingCancel} />
                </Form.Item>
              )
            })}
            <div style={{ marginTop: '20px' }}>
              <span style={{ marginRight: '20px' }}>新人接收礼物限制 <Tooltip title="指注册在配置天数内的新用户每日接收礼物的最大额度（元）。超出后，发送方发送礼物时会提示对应文案。" ><QuestionCircleFilled /></Tooltip></span>
              <TheSwitch haspermi={["wallet:setting:giftsForTheBrideAndGroom"]} checked={newPaySwitch3} onChange={this.newPay3} />
            </div>
            <div style={{ marginTop: '20px', width: '80vw' }}>
              {
                newPayArr3.map(item => {
                  return <div>
                    新人注册第【{item.startDay}-{item.endDay}】天，单日接收礼物金额额度为【{item.amountPerDay}】元，超出后提示文案为【{item.noticeMessage}】
                  </div>
                })
              }
            </div>
            <div style={{ marginTop: '20px', paddingLeft: '300px' }}>
              <TheButton haspermi={["wallet:setting:giftEdit"]} type="primary" onClick={this.showModalNewPay3}>编辑</TheButton>
            </div>
            <div style={{ marginTop: '20px' }}>
              <span style={{ marginRight: '20px' }}>新人赠送礼物限制 <Tooltip title="指注册在配置天数内的新用户每日发送礼物的最大额度（元）。超出后，发送方发送礼物时会提示对应文案。 " ><QuestionCircleFilled /></Tooltip></span>
              <TheSwitch haspermi={["wallet:setting:giftsForTheBrideAndGroomSend"]} checked={newPaySwitch3Send} onChange={this.newPay3Send} />
            </div>
            <div style={{ marginTop: '20px', width: '80vw' }}>
              {
                newPayArr3Send.map(item => {
                  return <div>
                    新人注册第【{item.startDay}-{item.endDay}】天，单日赠送礼物金额额度为【{item.amountPerDay}】元，超出后提示文案为【{item.noticeMessage}】
                  </div>
                })
              }
            </div>
            <div style={{ marginTop: '20px', paddingLeft: '300px' }}>
              <TheButton haspermi={["wallet:setting:giftEditSend"]} type="primary" onClick={() => this.showModalNewPaySend('新人赠送礼物限制', newPayArr3Send, '编辑新人赠送礼物限制')} >编辑</TheButton>
            </div>
            {isShow3 && <WalletRestrictions ref={this.ChildRef3} title={title3} arr={arr3} save={this.saveModal3} tips="编辑新人接收礼物限制" />}
          </Form>
        </div>
        {isShow4 && <WalletRestrictions ref={this.ChildRef4} title={titleNum} arr={arr4} save={this.saveModal4} tips={tips} />}
      </div>
    );
  }
}